/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.letmeshare.pedagogue.examination;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import org.letmeshare.pedagogue.basic.entities.Event;
import org.letmeshare.pedagogue.core.entities.Group;
import org.letmeshare.pedagogue.core.entities.Party;
import org.letmeshare.pedagogue.core.entities.Person;
import org.letmeshare.pedagogue.core.validation.ValidationException;
import org.letmeshare.pedagogue.core.validation.Validator;

/**
 *
 * @author aby
 */
@Entity
@NamedQueries({
@NamedQuery(name =Examination.GET_ALL_PASSED_CANDIDATES,query = "SELECT R.candidate FROM Result R WHERE R.examination=:examination "
        + "AND R.isPassed=true" ),
@NamedQuery(name =Examination.GET_ALL_PASSED_CANDIDATES,query = "SELECT R.candidate FROM Result R WHERE R.examination=:examination "
        + "AND R.isPassed=true" ),
@NamedQuery(name =Examination.GET_ALL_PASSED_RESULT,query = "SELECT R FROM Result R WHERE R.examination=:examination "
        + "AND R.isPassed=true" ),
@NamedQuery(name =Examination.GET_ALL_FAILED_RESULT,query = "SELECT R FROM Result R WHERE R.examination=:examination "
        + "AND R.isPassed=false" ),
@NamedQuery(name =Examination.GET_ALL_RESULT,query = "SELECT R FROM Result R WHERE R.examination=:examination" )})
public class Examination extends Event implements Serializable,Validator {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private String id;
    @OneToMany
    private Group candidates;
    @OneToMany
    private Group evaluators; 
    @OneToMany
    private GradingSystem grade;
    private float minPassMark,maxMark;
    
    
    
    public void addCandidate(Party candidate) {
        if (candidates == null) {
            candidates = new Group();
        }
        candidates.add(candidate);
    }

    public void addCandidates(List<Party> candidates) {
        if (this.candidates == null) {
            this.candidates = new Group();
        }
        this.candidates.add(candidates);
    }
    public void addEvaluater(Party candidate) {
        if (evaluators == null) {
            evaluators = new Group();
        }
        evaluators.add(candidate);
    }

    public void addEvaluators(List<Party> candidates) {
        if (this.evaluators == null) {
            this.evaluators = new Group();
        }
        this.evaluators.add(candidates);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Examination)) {
            return false;
        }
        Examination other = (Examination) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }
    @Override
    public void validate() throws ValidationException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String toString() {
        return "org.letmeshare.pedagogue.examination.Examination[ id=" + id + " ]";
    }


    public Group getCandidates() {
        return candidates;
    }

    public Group getEvaluators() {
        return evaluators;
    }

    public GradingSystem getGrade() {
        return grade;
    }

    public float getMinPassMark() {
        return minPassMark;
    }

    public float getMaxMark() {
        return maxMark;
    }

    public void setGrade(GradingSystem grade) {
        this.grade = grade;
    }

    public void setMinPassMark(float minPassMark) {
        this.minPassMark = minPassMark;
    }

    public void setMaxMark(float maxMark) {
        this.maxMark = maxMark;
    }

    
    public static final String GET_ALL_PASSED_CANDIDATES="GET_ALL_PASSED_STUDENTS";
    public static final String GET_ALL_FAILED_CANDIDATES="GET_ALL_FAILED_RESULT";
    public static final String GET_ALL_PASSED_RESULT="GET_ALL_PASSED_RESULT";
    public static final String GET_ALL_FAILED_RESULT="GET_ALL_FAILED_RESULT";
    public static final String GET_ALL_RESULT="GET_ALL_RESULT";
    
}
